home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1047 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: cs.mu.OZ.AU!bounce-back
  2. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: sample auto_ptr template
  5. Date: 12 Apr 96 12:46:05 GMT
  6. Organization: -
  7. Approved: fjh@cs.mu.oz.au
  8. Message-ID: <fjh-960412-224606@cs.mu.oz.au>
  9. References: <009A04DA6A831C40.49800EAC@ittpub.nl> <bill-0504961003150001@bgibbons.vip.best.com> <4k4noe$igl@jabba.lehman.com> <KANZE.96Apr9115532@gabi.gabi-soft.fr> <4kjqam$qs6@jabba.lehman.com>
  10. NNTP-Posting-Host: munta.cs.mu.oz.au
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMW5Qs+EDnX0m9pzZAQFF9wF9Gr8cS6QZpV64YO/IKiifEKvAYOCworxK
  13.     rLEofBETnXvWMqJe6KBncEvPSrVHKs+7
  14.     =iJo9
  15.  
  16. ajay@lehman.com (Ajay Kamdar) writes:
  17.  
  18. >The following example demonstrates why allowing exceptions to
  19. >propogate out of destructors is more trouble than it is worth:
  20. >
  21. >   auto_ptr<X>  get_X()
  22. >   {
  23. >      auto_ptr<X> p    = new X;
  24. >      auto_ptr<X> temp = new X;
  25. >      BadIdea     b1; // throws an exception in dtor
  26. >      BadIdea     b2; // throws an exception in dtor
  27. >
  28. >      // ... stuff
  29. >
  30. >      return p;
  31. >   }
  32. >
  33. >When b2 is destructed, it throws an exception. So what happens
  34. >next?
  35. >
  36. >Does the run time system try to continue to destruct b1, temp,
  37. >and p?
  38.  
  39. Yes.
  40.  
  41. >If it does, b1's destructor is also going to thow an
  42. >exception. If I interpret 15.5.1 in theApril '95 CD correctly
  43. >(I don't have access to any later drafts), terminate() is called
  44. >because of the exception propagating out of b1's destructor.
  45.  
  46. That's right.  I'm pretty sure this hasn't changed in the more recent drafts.
  47.  
  48. >If on the other hand the run time system abandons executing
  49. >the other destuctors in get_X() after b2's destructor has
  50. >thrown an exception,
  51.  
  52. Such an implementation would not be conforming.
  53.  
  54. (Incidentally, I agree quite strongly with the arguments voiced by
  55. Ajay Kamdar in this thread.)
  56.  
  57. --
  58. Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
  59. WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
  60. PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
  61. ---
  62. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  63. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  64. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  65. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  66. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  67.